﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyShopThoiTrang.QuanLyShopThoiTrang_BUS_WS;

namespace QuanLyShopThoiTrang
{
    public partial class TraCuuNhanVien : Form
    {
        QLSTT_BUSSoapClient ws = new QLSTT_BUSSoapClient();
        QuanLyNhanVien qlnv;
        public TraCuuNhanVien()
        {
            InitializeComponent();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
                comboBox2.Enabled = true;
            else
                comboBox2.Enabled = false;
        }

        public void Set(QuanLyNhanVien ql)
        {
            qlnv = ql;
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox2.Checked)
                comboBox1.Enabled = true;
            else
                comboBox1.Enabled = false;
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox3.Checked)
                dateTimePicker1.Enabled = true;
            else
                dateTimePicker1.Enabled = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            NhanVien nv = new NhanVien();

            nv.NhanVien_Ho = textBox1.Text;
            nv.NhanVien_Ten = textBox11.Text;
            nv.NhanVien_TenLot = textBox5.Text;

            if (checkBox1.Checked)
            {
                LoaiNhanVien lnv = (LoaiNhanVien)comboBox2.SelectedItem;
                nv.MaLoaiNhanVien = lnv.MaLoaiNhanVien;
            }
            else
                nv.MaLoaiNhanVien = 0;

            if (checkBox2.Checked)
            {
                nv.NhanVien_Phai = comboBox1.Text;
            }
            else
                nv.NhanVien_Phai = "";

            nv.NhanVien_DiaChi = textBox3.Text;

            if (checkBox3.Checked)
                nv.NhanVien_NgaySinh = dateTimePicker1.Value;
            else
                nv.NhanVien_NgaySinh = null;

            nv.NhanVien_SoDienThoai = textBox4.Text;
            nv.NhanVien_Email = textBox7.Text;

            if (textBox9.Text == "")
                nv.NhanVien_Luong = 0;
            else
            {
                if (ws.KiemTraDouble(textBox9.Text))
                    nv.NhanVien_Luong = double.Parse(textBox9.Text);
                else
                {
                    MessageBox.Show("Lương không hợp lệ");
                    return;
                }
            }

            nv.NhanVien_TenDangNhap = textBox2.Text;

            qlnv.TraCuu(nv);
            Close();
        }

        private void TraCuuNhanVien_Load(object sender, EventArgs e)
        {
            comboBox1.Enabled = true;
            comboBox1.Items.Add("Nam");
            comboBox1.Items.Add("Nữ");
            comboBox1.SelectedIndex = 0;
            comboBox1.Enabled = false;
            List<LoaiNhanVien> listLNV = ws.LoaiNhanVien_LayDanhSach();
            comboBox2.DataSource = listLNV;
            comboBox2.DisplayMember = "LoaiNhanVien_Ten";
        }
    }
}
